package com.qf.fmall2302.wxpay;

import com.github.wxpay.sdk.WXPay;
import com.github.wxpay.sdk.WXPayConfig;

import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public class WxSdkUtils {


    public String getPayUrl(String orderid,String desc,Long amount) throws Exception {
        // 创建sdk的核心对象
        WXPay wxPay = new WXPay(new MyWxConfig());

        HashMap<String, String> map = new HashMap<>();
        String randomstr = UUID.randomUUID().toString().replaceAll("-", "");
        map.put("nonce_str",randomstr); // 长度32个字符的随机字符串，干扰项
        map.put("body",desc); // 订单描述信息

        map.put("out_trade_no",orderid); // 订单编号
        map.put("total_fee","1");  // 1 分钱
        map.put("trade_type","NATIVE"); // 支付类型
        map.put("fee_type","CNY"); // 币种
        map.put("notify_url","http://47.118.45.73:8080/pay/callback"); // 商户提供的回调地址
        map.put("sign_type","MD5"); // 签名算法

        Map<String, String> result = wxPay.unifiedOrder(map);
        return result.get("code_url");
    }

    public static String queryStatus(String orderid) throws Exception {
        WXPay wxPay = new WXPay(new MyWxConfig());
        HashMap<String, String> map = new HashMap<>();
        map.put("out_trade_no",orderid);
        Map<String, String> result = wxPay.orderQuery(map);
        return result.get("trade_state");
    }


    public static void main(String[] args) throws Exception {

        String orderid = "202308241617987";
        WXPay wxPay = new WXPay(new MyWxConfig());
        HashMap<String, String> map = new HashMap<>();
        map.put("out_trade_no",orderid);
        Map<String, String> result = wxPay.orderQuery(map);
        System.out.println(result);

    }

}
